package com.tapjoy;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.util.Timer;
import java.util.TimerTask;

public class TapjoyDisplayAd
{
  public static final String TAPJOY_DISPLAY_AD = "Banner Ad";
  private static String adClickURL;
  private static int bannerHeight;
  private static int bannerWidth;
  private static Bitmap bitmapImage;
  private static TapjoyDisplayAdNotifier displayAdNotifier;
  private static String displayAdSize;
  public static String displayAdURLParams;
  private static TapjoyURLConnection tapjoyURLConnection = null;
  View adView;
  private boolean autoRefresh;
  private Context context;
  long elapsed_time;
  Bitmap lastAd;
  Timer resumeTimer;
  Timer timer;

  public TapjoyDisplayAd(Context paramContext)
  {
    setDisplayAdSize("640x100");
    this.context = paramContext;
    tapjoyURLConnection = new TapjoyURLConnection();
  }

  public static Bitmap getBitmapImage()
  {
    return bitmapImage;
  }

  public static String getLinkURL()
  {
    return adClickURL;
  }

  public void enableAutoRefresh(boolean paramBoolean)
  {
    this.autoRefresh = paramBoolean;
  }

  public String getBannerAdSize()
  {
    return getDisplayAdSize();
  }

  public void getDisplayAd(TapjoyDisplayAdNotifier paramTapjoyDisplayAdNotifier)
  {
    TapjoyLog.i("Banner Ad", "Get Banner Ad");
    getDisplayAd(null, paramTapjoyDisplayAdNotifier);
  }

  public void getDisplayAd(String paramString, TapjoyDisplayAdNotifier paramTapjoyDisplayAdNotifier)
  {
    TapjoyLog.i("Banner Ad", "Get Banner Ad, currencyID: " + paramString);
    displayAdNotifier = paramTapjoyDisplayAdNotifier;
    displayAdURLParams = TapjoyConnectCore.getURLParams();
    displayAdURLParams = displayAdURLParams + "&publisher_user_id=" + TapjoyConnectCore.getUserID();
    displayAdURLParams = displayAdURLParams + "&size=" + displayAdSize;
    if (paramString != null)
      displayAdURLParams = displayAdURLParams + "&currency_id=" + paramString;
    GetBannerAdTask localGetBannerAdTask = new GetBannerAdTask(null);
    String[] arrayOfString = new String[2];
    arrayOfString[0] = "https://ws.tapjoyads.com/display_ad.html?";
    arrayOfString[1] = displayAdURLParams;
    localGetBannerAdTask.execute(arrayOfString);
  }

  public String getDisplayAdSize()
  {
    return displayAdSize;
  }

  public void setBannerAdSize(String paramString)
  {
    setDisplayAdSize(paramString);
  }

  public void setDisplayAdSize(String paramString)
  {
    displayAdSize = paramString;
    if (paramString.equals("320x50"))
    {
      bannerWidth = 320;
      bannerHeight = 50;
    }
    do
    {
      return;
      if (paramString.equals("640x100"))
      {
        bannerWidth = 640;
        bannerHeight = 100;
        return;
      }
    }
    while (!paramString.equals("768x90"));
    bannerWidth = 768;
    bannerHeight = 90;
  }

  private class CheckForResumeTimer extends TimerTask
  {
    private CheckForResumeTimer()
    {
    }

    public void run()
    {
      TapjoyDisplayAd localTapjoyDisplayAd = TapjoyDisplayAd.this;
      localTapjoyDisplayAd.elapsed_time = (10000L + localTapjoyDisplayAd.elapsed_time);
      TapjoyLog.i("Banner Ad", "banner elapsed_time: " + TapjoyDisplayAd.this.elapsed_time + " (" + TapjoyDisplayAd.this.elapsed_time / 1000L / 60L + "m " + TapjoyDisplayAd.this.elapsed_time / 1000L % 60L + "s)");
      if (TapjoyDisplayAd.this.adView == null)
        cancel();
      do
      {
        return;
        TapjoyLog.i("Banner Ad", "adView.isShown: " + TapjoyDisplayAd.this.adView.isShown());
        if ((TapjoyDisplayAd.this.adView.isShown()) && (TapjoyConnectCore.getInstance() != null))
        {
          TapjoyLog.i("Banner Ad", "call connect");
          TapjoyConnectCore.getInstance().callConnect();
          cancel();
        }
      }
      while (TapjoyDisplayAd.this.elapsed_time < 1200000L);
      cancel();
    }
  }

  private class GetBannerAdTask extends AsyncTask<String, Void, TapjoyHttpURLResponse>
  {
    private GetBannerAdTask()
    {
    }

    protected TapjoyHttpURLResponse doInBackground(String[] paramArrayOfString)
    {
      return TapjoyDisplayAd.tapjoyURLConnection.getResponseFromURL("https://ws.tapjoyads.com/display_ad.html?", TapjoyDisplayAd.displayAdURLParams);
    }

    protected void onPostExecute(TapjoyHttpURLResponse paramTapjoyHttpURLResponse)
    {
      if (paramTapjoyHttpURLResponse != null)
        switch (paramTapjoyHttpURLResponse.statusCode)
        {
        default:
          TapjoyDisplayAd.displayAdNotifier.getDisplayAdResponseFailed("No ad to display.");
        case 200:
        }
      do
      {
        return;
        WebView localWebView = new WebView(TapjoyDisplayAd.this.context);
        localWebView.getSettings().setJavaScriptEnabled(true);
        localWebView.setWebViewClient(new WebViewClient()
        {
          public boolean shouldOverrideUrlLoading(WebView paramAnonymousWebView, String paramAnonymousString)
          {
            Intent localIntent = new Intent(TapjoyDisplayAd.this.context, TJCOffersWebView.class);
            localIntent.putExtra("DISPLAY_AD_URL", paramAnonymousString);
            localIntent.setFlags(268435456);
            TapjoyDisplayAd.this.context.startActivity(localIntent);
            if (TapjoyDisplayAd.this.resumeTimer != null)
              TapjoyDisplayAd.this.resumeTimer.cancel();
            TapjoyDisplayAd.this.elapsed_time = 0L;
            TapjoyDisplayAd.this.resumeTimer = new Timer();
            TapjoyDisplayAd.this.resumeTimer.schedule(new TapjoyDisplayAd.CheckForResumeTimer(TapjoyDisplayAd.this, null), 10000L, 10000L);
            return true;
          }
        });
        localWebView.setLayoutParams(new ViewGroup.LayoutParams(TapjoyDisplayAd.bannerWidth, TapjoyDisplayAd.bannerHeight));
        localWebView.setInitialScale(100);
        localWebView.setBackgroundColor(0);
        localWebView.loadDataWithBaseURL("https://ws.tapjoyads.com/", paramTapjoyHttpURLResponse.response, "text/html", "utf-8", null);
        if (TapjoyDisplayAd.this.adView != null)
          TapjoyDisplayAd.this.lastAd = TapjoyUtil.createBitmapFromView(TapjoyDisplayAd.this.adView);
        TapjoyDisplayAd.this.adView = localWebView;
        if (TapjoyDisplayAd.this.lastAd != null)
          TapjoyDisplayAd.this.adView.setBackgroundDrawable(new BitmapDrawable(TapjoyDisplayAd.this.lastAd));
        TapjoyDisplayAd.displayAdNotifier.getDisplayAdResponse(TapjoyDisplayAd.this.adView);
        if (TapjoyDisplayAd.this.timer != null)
        {
          TapjoyDisplayAd.this.timer.cancel();
          TapjoyDisplayAd.this.timer = null;
        }
      }
      while ((!TapjoyDisplayAd.this.autoRefresh) || (TapjoyDisplayAd.this.timer != null));
      TapjoyLog.i("Banner Ad", "will refresh banner ad in 15s...");
      TapjoyDisplayAd.this.timer = new Timer();
      TapjoyDisplayAd.this.timer.schedule(new TapjoyDisplayAd.RefreshTimer(TapjoyDisplayAd.this, null), 15000L);
    }

    protected void onProgressUpdate(Void[] paramArrayOfVoid)
    {
    }
  }

  private class RefreshTimer extends TimerTask
  {
    private RefreshTimer()
    {
    }

    public void run()
    {
      TapjoyLog.i("Banner Ad", "refreshing banner ad...");
      TapjoyDisplayAd.this.getDisplayAd(TapjoyDisplayAd.displayAdNotifier);
      TapjoyDisplayAd.this.timer.cancel();
      TapjoyDisplayAd.this.timer = null;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.tapjoy.TapjoyDisplayAd
 * JD-Core Version:    0.6.2
 */